import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 放用户信息,因为多个页面/组件会用到token数据
    // 用token判断用户是否登录,发请求传token
    token: localStorage.getItem('TOUTIAO_TOKEN')
  },
  mutations: {
    setToken (state, payload) {
      state.token = payload
      localStorage.setItem('TOUTIAO_TOKEN', payload)
    },
    removeToken (state) {
      state.token = null
      localStorage.removeItem('TOUTIAO_TOKEN')
    }
  },
  actions: {
  },
  modules: {
  }
})
